package com.d2.common.excel;


import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.metadata.WriteTable;
import com.alibaba.excel.write.metadata.style.WriteCellStyle;
import com.alibaba.excel.write.metadata.style.WriteFont;
import com.alibaba.excel.write.style.HorizontalCellStyleStrategy;
import org.apache.poi.ss.usermodel.IndexedColors;

import java.io.OutputStream;
import java.lang.reflect.Array;
import java.util.*;


public class ExcelUtils {
    public static void simpleExport(OutputStream os, List<String> header, List<List<String>> data) {
        ExcelWriter excelWriter = EasyExcel.write(os).build();
        WriteSheet writeSheet = EasyExcel.writerSheet().build();
        List<List<String>> headers = head(header);
        writeSheet.setHead(headers);
        writeSheet.setSheetNo(0);
        data.add(Arrays.asList("数据1", "数据2"));
        data.add(Arrays.asList("数据3", "数据4"));
        excelWriter.write(data, writeSheet).finish();
    }

    private static List<List<String>> head(List<String> header) {
        List<List<String>> result = new ArrayList<>();
        for (String s:header) {
            result.add(Collections.singletonList(s));
        }
        return result;
    }
}
